/**
  ******************************************************************************
  * @file    main.c 
  * @author  Tmax Sco
  * @version V1.0.0
  * @date    2017-2-22
  * @brief   完成速度环位置环等初始化任务
  ******************************************************************************
  * @attention
  * 主要程序执行在TIM2_IRQHandler、CAN1_RX0_IRQHandler、CAN2_RX0_IRQHandler中查找
  ******************************************************************************
  */ 

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_it.h"
#include "timer.h"
#include "gpio.h"
#include "usart.h"
#include "misc.h"
#include "can.h"
#include "math.h"
#include "stdio.h"
#include "arm_math.h"
#include "ctrl.h"
#include "comm.h"

extern DriverType Driver[8];
extern MotorType Motor[8];

void init(void)
{
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	
	    
	USART3_DMA_Init(115200);//外接串口初始化
	LEDInit();
	CAN_Config(CAN1,1000,GPIOB,GPIO_Pin_8, GPIO_Pin_9); 
	CAN_Config(CAN2, 1000,GPIOB,GPIO_Pin_5, GPIO_Pin_6);

	TIM_Init(TIM2,999,83,0,0);					//1ms控制一次
  	TIM_Cmd(TIM2,ENABLE);	
	
	DriverInit();//初始化速度环以及位置环参数
	
	TIM_Delayms(TIM3,200); //用于延时用的定时器
	
}
int main(void)
{
	init();

	//经典商店带啊
	USART_SendData(USART3,'a');
	USART_OUT(USART3, "hell0=%d\r\n",10);
	uint8_t buf[8] = {0} ;
	for(int i = 0 ; i < 8 ; i++){
		buf[i] = 'a' + i;
	}
	CAN_TxMsg(CAN1,1,buf,8);
	TIM_Delayms(TIM3,500);
	while(1)
	{
		CANRespond();
		// Driver[0].posCtrl.desiredPos = 19 * 8192; 
		//TIM_Delayms(TIM3,100);
		//VelCtrlTest(300.0f,500);
		// Driver[2].velCtrl.desiredVel[CMD] = 8.192f * 180;;
	}
}




/************************ (C) COPYRIGHT 2019 ACTION ********************/

